package com.wangshang.general.order.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.general.order.po.ShopOrder;

/**
 * A data access object (DAO) providing persistence and search support for
 * ShopOrder entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.wangshang.general.order.po.ShopOrder
 * @author MyEclipse Persistence Tools
 */

public class ShopOrderDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ShopOrderDAO.class);
	// property constants
	public static final String USER_IDENTIFY = "userIdentify";
	public static final String WORKER_ID = "workerId";
	public static final String HALL_ID = "hallId";
	public static final String USER_NAME = "userName";
	public static final String USER_ID_TYPE = "userIdType";
	public static final String USER_ID = "userId";
	public static final String USER_CONNECT = "userConnect";
	public static final String USER_ADDR = "userAddr";
	public static final String CASH_PAY = "cashPay";
	public static final String TOTAL_COST = "totalCost";
	public static final String ORDER_STATUS = "orderStatus";
	public static final String WAY_OF_DELIVERY = "wayOfDelivery";
	public static final String RESULT_FOR_UNEXCEPTED = "resultForUnexcepted";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";
	public static final String DELIVERIER_NAME = "deliverierName";

	protected void initDao() {
		// do nothing
	}

	public void save(ShopOrder transientInstance) {
		log.debug("saving ShopOrder instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ShopOrder persistentInstance) {
		log.debug("deleting ShopOrder instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ShopOrder findById(java.lang.String id) {
		log.debug("getting ShopOrder instance with id: " + id);
		try {
			ShopOrder instance = (ShopOrder) getHibernateTemplate().get(
					"com.wangshang.general.order.ShopOrder", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ShopOrder instance) {
		log.debug("finding ShopOrder instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ShopOrder instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ShopOrder as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserIdentify(Object userIdentify) {
		return findByProperty(USER_IDENTIFY, userIdentify);
	}

	public List findByWorkerId(Object workerId) {
		return findByProperty(WORKER_ID, workerId);
	}

	public List findByHallId(Object hallId) {
		return findByProperty(HALL_ID, hallId);
	}

	public List findByUserName(Object userName) {
		return findByProperty(USER_NAME, userName);
	}

	public List findByUserIdType(Object userIdType) {
		return findByProperty(USER_ID_TYPE, userIdType);
	}

	public List findByUserId(Object userId) {
		return findByProperty(USER_ID, userId);
	}

	public List findByUserConnect(Object userConnect) {
		return findByProperty(USER_CONNECT, userConnect);
	}

	public List findByUserAddr(Object userAddr) {
		return findByProperty(USER_ADDR, userAddr);
	}

	public List findByCashPay(Object cashPay) {
		return findByProperty(CASH_PAY, cashPay);
	}

	public List findByTotalCost(Object totalCost) {
		return findByProperty(TOTAL_COST, totalCost);
	}

	public List findByOrderStatus(Object orderStatus) {
		return findByProperty(ORDER_STATUS, orderStatus);
	}

	public List findByWayOfDelivery(Object wayOfDelivery) {
		return findByProperty(WAY_OF_DELIVERY, wayOfDelivery);
	}

	public List findByResultForUnexcepted(Object resultForUnexcepted) {
		return findByProperty(RESULT_FOR_UNEXCEPTED, resultForUnexcepted);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findByDeliverierName(Object deliverierName) {
		return findByProperty(DELIVERIER_NAME, deliverierName);
	}

	public List findAll() {
		log.debug("finding all ShopOrder instances");
		try {
			String queryString = "from ShopOrder";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ShopOrder merge(ShopOrder detachedInstance) {
		log.debug("merging ShopOrder instance");
		try {
			ShopOrder result = (ShopOrder) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ShopOrder instance) {
		log.debug("attaching dirty ShopOrder instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ShopOrder instance) {
		log.debug("attaching clean ShopOrder instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ShopOrderDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ShopOrderDAO) ctx.getBean("ShopOrderDAO");
	}
}